package com.lanou3g.hw0510;


import org.apache.commons.io.IOUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;

/**
 * Created by dllo on 18/5/10.
 */
@WebServlet(name = "DownLoadServlet", urlPatterns = "/down")
public class DownLoadServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf8");
//
//        String filename="作业.zip";
        // 把汉字转换成URL编码
//        filename= URLEncoder.encode(filename,"utf8");

        //response.setHeader("Content-Disposition", "attachment;filename="+filename);

        response.setHeader("Content-Disposition", "attachment;filename=bbb.gif");

        InputStream is = getServletContext().getResourceAsStream("file/bbb.gif");

        response.getOutputStream().write(IOUtils.toByteArray(is));

    }
}
